package com.xwj.aop;

import java.lang.reflect.Proxy;

/**
 * @author xwj
 * @date 2020/4/11
 */
public class AopTest {
    public static void main(String[] args) {
        // 1. 创建一个 MethodInvocation 实现类
        MethodInvocation log = new LogMethodInvocation();
        HelloServiceImpl helloServiceImpl = new HelloServiceImpl();

        // 2. 创建一个 Advice
        Advice beforeAdvice = new BeforeAdvice(helloServiceImpl, log);

        // 3. 为目标对象生成代理
        HelloService helloServiceImplProxy = (HelloService) Proxy.newProxyInstance(helloServiceImpl.getClass().getClassLoader(),
                helloServiceImpl.getClass().getInterfaces(), beforeAdvice);
        helloServiceImplProxy.hello();
    }
}
